package main

import (
	"context"
	"google.golang.org/grpc"
	"gosecond/ch16grpc/grpclearn/proto"
	"net"
)

type Server struct {

}

func (s *Server) SayHello(ctx context.Context, request *proto.HelloRequest) (*proto.HelloReply, error){
	return &proto.HelloReply{
		Message:"hello "+request.Name,
	},nil
}


func main() {
	//1.生成server
	g := grpc.NewServer()
	//注册服务
	proto.RegisterGreeterServer(g, &Server{})
	//启动
	listener, err := net.Listen("tcp", "0.0.0.0:8088")
	if err != nil {
		panic("fail to listen: " + err.Error())
	}
	err = g.Serve(listener)
	if err != nil {
		panic("fail to start grpc")
	}
}